//ATM



var ATM = function (){
    
//    var _address = address;
    
    var _costumers = {};
    
    var _id = Math.floor(Math.random()*900000000) + 100000000;
    
    this.getId = function (){
        document.getElementById("messages").innerHTML= '<p>The ATM id is'+ _id + '</p>';
        return _id;
    };

//    this.getAddress = function (){
//        document.getElementById("messages").innerHTML = "The ATM number " +_id + " is located in "+ _address;
//        return _address;
//    };

    this.createCostumer = function (){
        firstName = function (){
            getElementById("first_name");
        }
        lastName = function (){
            getElementById("last_name");
        }
        var costumer = new Costumer (firstName, lastName);
        _costumers[costumer.getId()] = costumer ;
        return costumer;
    };   
    
    this.deleteCostumer = function (costumerId){
        delete _costumers [costumerId];
        document.getElementById("messages").innerHTML = "The costumer " +costumerId + " has been deleted";

    };
    
    this.getCostumer = function (costumerId) {
        return _costumers[costumerId];
    }
    
    this.getCostumers = function (){
        return _costumers;
    }  
    
    document.getElementById("messages").innerHTML= '<p>The ATM '+ _id + ' was successfully created</p>';
    
    //need to set timeout from the first message to the second one
    
    document.getElementById("messages").innerHTML= '<p>First of all, we need you to register in our ATM:</p>' ;
    document.getElementById("touchpad").innerHTML= '<p><label for="first_name">First name</label><input id="first_name" name="first_name" type="text" placeholder="Type your first name"/></p><p><label for="last_name">Last name</label><input id="last_name" name="last_name" type="text" placeholder="Type your last name"/></p><p><input type="submit" name="new_costumer" id="new_costumer" value="Register" onclick = "atm1.createCostumer()"/></p>';
    
//    return ATM;
} 

// COSTUMER  

var Costumer = function (firstName, lastName) {
    
    var _firstName = firstName;
    
    var _lastName = lastName;
    
    var _fullName = firstName + " " + lastName;
    
    var _id = Math.floor(Math.random()*900000000) + 100000000;
    
    var _password = Math.floor(Math.random()*9000) + 1000;
    
    var accounts = {};   
    
    this.getId = function (){
        return _id;
    };
    
    this.getName = function (){
        return _fullName;
    };
    
    this.getPassword = function (){
        return _password;
    };
    
    this.createAccount = function (initialBalance) {
        var account = new Account (initialBalance);
        accounts[account.getId()] = account;
        return account;
    };
    
    document.write("Thank you Mr. " + _fullName + ", you have been succesfully registered to Bep Bank. Your costumer Id is "+ _id + " and your secret password is " + _password )

}

//ACCOUNT

var Account = function (initialBalance) {
    
    var _id = Math.floor(Math.random()*900000000) + 100000000;
    
    var _currentBalance = initialBalance;
    
    this.getId = function (){
        return _id;
    };
    
    this.getCurrentBalance = function (){
        return _currentBalance;
    };
    
    this.deposit = function (depositAmount) {
        _currentBalance += depositAmount;
        return _currentBalance;
    }
    
    this.withdrawal = function (withdrawalAmount) {
        _currentBalance += withdrawalAmount;
        return _currentBalance;
    }   
    document.write("Your account number " + _id + " has been created with an initial balance of "+ _currentBalance )

}


//new ATM ("Wallstreet 888, Manhattan, New York");


//var sergi = atm1.createCostumer("Sergi", "Gómez");
//
//var sergiAccount1 = sergi.createAccount(3000);







































